package com.mapproject.industrymap.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mapproject.industrymap.entity.ChildGeomEntity;
import com.mapproject.industrymap.entity.EstateInfoEntity;
import com.mapproject.industrymap.entity.PersonEstateEntity;
import com.mapproject.industrymap.entity.PublicEstateEntity;
import com.mapproject.industrymap.mapper.FoodassetsChildInfoMapper;
import com.mapproject.industrymap.mapper.PersonEstateMapper;
import com.mapproject.industrymap.mapper.PublicEstateMapper;
import com.mapproject.industrymap.service.FoodassetsChildInfoService;
import com.mapproject.industrymap.utils.ReturnValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service
public class FoodassetsChildInfoServiceImpl implements FoodassetsChildInfoService {
    @Autowired
    FoodassetsChildInfoMapper foodassetsChildInfoMapper;
   public ReturnValue insertdata(Map<String,Object> maps,String type){
       try{
               String rowguid = UUID.randomUUID().toString(); // 主键uuid
               JSONObject json = new JSONObject(maps);
               Object str = json.get("properties");
               Object geo=json.get("geometry");
               EstateInfoEntity estateInfoEntity = JSON.parseObject(JSON.toJSONString(str), EstateInfoEntity.class);
               estateInfoEntity.setRowguid(rowguid);
               estateInfoEntity.setPublicorperson(type);
               estateInfoEntity.setStatus("1");
               estateInfoEntity.setGeom(JSONObject.toJSONString(geo));
               int result=foodassetsChildInfoMapper.insertEstateData(estateInfoEntity);
               return new ReturnValue(200,"新增数据:"+result,rowguid);
       }catch (Exception ex){
           return new ReturnValue(500,"",ex);
       }

   }
   public ReturnValue querydata(String rowguid,String type){
       try {
           String result=foodassetsChildInfoMapper.queryData(rowguid,type);

           return new ReturnValue(200,"查询成功",JSON.parse(result));
       }catch (Exception ex){
           return new ReturnValue(500,"查询失败",ex);
       }

   }
    public ReturnValue updatedata(Map<String,Object> maps,String type){
       try{
               JSONObject json = new JSONObject(maps);
               Object str = json.get("properties");
               Object geo=json.get("geometry");
               EstateInfoEntity estateInfoEntity = JSON.parseObject(JSON.toJSONString(str), EstateInfoEntity.class);
               String rowguid=estateInfoEntity.getRowguid();
               estateInfoEntity.setPublicorperson(type);
               int result=foodassetsChildInfoMapper.updateEstateData(estateInfoEntity);
               return new ReturnValue(200,"更新数据:"+result,rowguid);

       }catch (Exception ex){
           return new ReturnValue(500,"",ex);
       }

    }
    public ReturnValue getestatelist(String rowguid){
        String result= foodassetsChildInfoMapper.getestatelist(rowguid);
       return new ReturnValue(200,"更新数据",JSON.parse(result));
    }

//
//   public int insertgeometry(Object geom,String torowguid,String type){
//       String rowguid = UUID.randomUUID().toString();
//       String geometry=JSONObject.toJSONString(geom);
//       ChildGeomEntity childGeomEntity=new ChildGeomEntity();
//       childGeomEntity.setGeom(geometry);
//       childGeomEntity.setRowguid(rowguid);
//       childGeomEntity.setTorowguid(torowguid);
//       childGeomEntity.setPublicorperson(type);
//       childGeomEntity.setStatus("1");
//       int ret=  foodassetsChildInfoMapper.insertgeom(childGeomEntity);
//       return ret;
//   }
//    public int updategeometry(Object geom,String torowguid,String type,String status){
//
//        String geometry=JSONObject.toJSONString(geom);
//        ChildGeomEntity childGeomEntity=new ChildGeomEntity();
//        childGeomEntity.setGeom(geometry);
//        childGeomEntity.setTorowguid(torowguid);
//        childGeomEntity.setPublicorperson(type);
//        childGeomEntity.setStatus(status);
//        int ret=  foodassetsChildInfoMapper.updategeom(childGeomEntity);
//        return ret;
//    }

}
